#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 10000;
const int M = 1e9 + 7;

int t;
string s;
string base[64];

void init()
{
    for (int i = 0; i < 64; i++)
    {
        base[i] = to_string(1ll<<i);
    }
}

int get_lcp(string a, string b)
{
    int j = 0;

    for (int i = 0; i < a.size(); i++)
        if (a[i] == b[j])
            j++;
        
    return j;
}

int main()
{
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0);
    init();
    cin >> t;
    while (t--)
    {
        cin >> s;

        int res = 100;
        for (int i = 0; i < 64; i++)
        {
            int lcs = get_lcp(s, base[i]);

            int temp = s.size() - lcs + base[i].size() - lcs;
            res = min(res, temp);
        }
        cout << res << endl;
    }
    return 0;
}